function cselectorChange()
{
    // 删除后面的select
    $(this).nextAll("select").remove();

    // 计算当前选中到id和拼起来的name
    var selects = $(this).siblings("select").andSelf();
    //var id = 0;
    var id = '';
    var names = new Array();
    for (i = 0; i < selects.length; i++)
    {
        sel = selects[i];
        if (sel.value > 0)
        {
            id = sel.value;
            name = sel.options[sel.selectedIndex].text;
            names.push(name);
        }
    }
	var object_id = $('#object_id');
	var object_show = $('#object_show');
	if (object_id.length > 0)
	{
		object_id.val(id);
	}
	if (object_show.length > 0)
	{
		object_show.val(names.join(''));
	}

    // ajax请求下级地区
    if (this.value > 0)
    {
        var _self = this;
        var url = '?app=portal&mod=getclass';
        $.getJSON(url, {'object_id':this.value,'type':$('#cselector_type').val()}, function(data){
            if (data)
            {
                if (data.length > 0)
                {
                    $("<select class='.cselector' style='width:auto'><option>请选择</option></select>").change(cselectorChange).insertAfter(_self);
                    var data  = data;
                    for (i = 0; i < data.length; i++)
                    {
                        $(_self).next("select").append("<option value='" + data[i].class_id + "'>" + data[i].class_name + "</option>");
                    }
                }
            }
            else
            {
                alert(data.msg);
            }
        });
    }
}

/* 地区选择函数 */
function cselectorInit(divId)
{
    $("#" + divId + " > select").change(cselectorChange); // select的onchange事件
    $("#" + divId + " > input:button[class='cselector']").click(cselectorEdit); // 编辑按钮的onclick事件
}

function cselectorEdit()
{
	$('#object_id').val('');
    $(this).siblings("select").show();
    $(this).siblings("strong").andSelf().hide();
}